package pcb.views.library 
{
	import com.intel.utils.TextRender;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.text.GridFitType;
	import flash.text.TextField;
	import pcb.models.vo.Annotation;
	
	/**
	 * ...
	 * @author ...
	 */
	public class AnnotationMC extends MovieClip
	{
		
		private var _text:String;
		private var _orientation:String = Annotation.TOP_RIGHT;
		
		public function AnnotationMC() 
		{
			
		}
		
		private function hideArrows():void 
		{
			this.getChildByName("topRight").visible = false;			
			this.getChildByName("topLeft").visible = false;
			this.getChildByName("bottomRight").visible = false;
			this.getChildByName("bottomLeft").visible = false;			
		}
		
		public function set text(value:String):void 
		{		
		
			trace("Setting the text!");
		
			_text = value;
			var tf:TextField = this.getChildByName("mcText") as TextField;
			
			//tf.border = true;
			//tf.gridFitType = GridFitType.NONE;
			
			TextRender.createLabel(tf, _text);
	
			if(tf.textHeight > 96) {
				gotoAndStop("large");
			} else if(tf.textHeight > 48) {
			  gotoAndStop("medium");
			}
		}
		
		public function set orientation(value:String):void 
		{
			_orientation = value;			
		}
		
		public function repositionTo(mc:DisplayObject):void 
		{	
			hideArrows();
			
			this.x = mc.x;
			this.y = mc.y;
			
			switch (_orientation) {
				case Annotation.TOP_RIGHT:
					this.x += (this.width / 2) + (mc.width / 2);
					this.y -= (this.height / 2) + (mc.height / 2);
					this.getChildByName("topRight").visible = true;
					break;
				case Annotation.TOP_LEFT:
					this.x -= (this.width / 2) + (mc.width / 2);
					this.y -= (this.height / 2) + (mc.height / 2);
					this.getChildByName("topLeft").visible = true;
					break;
				case Annotation.BOTTOM_RIGHT:
					this.x += (this.width / 2) + (mc.width / 2);
					this.y += (this.height / 2) + (mc.height / 2);
					this.getChildByName("bottomRight").visible = true;
					break;
				case Annotation.BOTTOM_LEFT:
					this.x -= (this.width / 2) + (mc.width / 2);
					this.y += (this.height / 2) + (mc.height / 2);
					this.getChildByName("bottomLeft").visible = true;
					break;
				case Annotation.CENTER_STAGE:
					//todo
					/*
					this.x += (this.width / 2) + (mc.width / 2);
					this.y -= (this.height / 2) + (mc.height / 2);
					this.getChildByName("topRight").visible = true;
					*/
					break;
					
			}
			
		}
	}
	
}